<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('角色列表')" />
    <style>
        .select-list ul li{
            width: 30%;
        }
        .select-list .select-time input {
            width: 64.5%;
        }
        .fa{
            margin-right: 5px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            订单名称：<input type="text" name="orderName" style="width: 64.5%;"/>
                        </li>
                        <li>
                            订单编号：<input type="text" name="orderNumber" style="width: 64.5%;"/>
                        </li>
                        <li>
                            订单状态：<select name="orderStatus" style="width: 64.5%;" th:with="type=${@dict.getType('business_order_type')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>订货时间： </label>
                            <input type="text" class="time-input" id="orderTime" name="orderTimeStr" placeholder="开始时间" />
                        </li>
                        <li class="select-time">
                            <label>发货时间： </label>
                            <input type="text" class="time-input" id="sendTime" name="sendTimeStr" placeholder="结束时间" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:order:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:order:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:order:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:order:export">
                <i class="fa fa-download"></i> 导出
            </a>-->
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:order:edit')}]];
    var detailFlag = [[${@permission.hasPermi('business:order:detail')}]];
    var statusFlag = [[${@permission.hasPermi('business:order:status')}]];
    var removeFlag = [[${@permission.hasPermi('business:order:remove')}]];
    var passFlag = [[${@permission.hasPermi('business:order:password')}]];
    var prefix = ctx + "order";
    let status = {
        1: '合同签订',
        2: '预付款到账',
        3: '效果图制作',
        4: '效果图确认',
        5: '订单下发',
        6: '模块拼接',
        7: '模拟屏制作',
        8: '模拟屏外接组装',
        9: '电子组件安装',
        10: '模拟屏外框组装',
        11: '拍照审核',
        12: '模拟屏成品确认',
        13: '包装',
        14: '全款到账',
        15: '移交物流',
        16: '货物出发',
        17: '货物到达',
        18: '全款到账',
        19: '通知防货',
        20: '获取签收'
    }
    $(function() {
        let params = {};
        if($("#orderName").val() != ""){
            params.orderName= $("#orderName").val()
        }
        if($("#orderNumber").val() != ""){
            params.orderNumber=$("#orderNumber").val()
        }
        if($("#orderStatus").val() != ""){
            params.orderStatus=$("#orderStatus").val()
        }
        if($("#orderTime").val() != ""){
            params.orderTime=new Date($("#orderTime").val())
        }
        if($("#sendTime").val() != ""){
            params.sendTime=new Date($("#sendTime").val())
        }
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "id",
            sortOrder: "desc",
            modalName: "订单",
            method: 'GET',
            columns: [{
                    checkbox: true
                },
                {
                    field: 'orderNumber',
                    title: '订单编号'
                },
                {
                    field: 'orderName',
                    title: '订单名称',
                    sortable: true
                },
                {
                    field: 'orderStatus',
                    title: '订单状态',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return status[value];
                    }
                },
                {
                    field: 'orderTime',
                    title: '订货时间',
                    sortable: true
                },
                {
                    field: 'sendTime',
                    title: '发货时间',
                    sortable: true
                },
                {
                    field: 'skillRequire',
                    title: '技术要求',
                    sortable: true
                },
                {
                    field: 'material',
                    title: '材质',
                    sortable: true
                },
                {
                    field: 'measure',
                    title: '尺寸',
                    sortable: true
                },
                {
                    field: 'pack',
                    title: '包装',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-eye"></i>查看详情</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + statusFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\')"><i class="fa fa-arrow-circle-o-up"></i>更新状态</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + passFlag + '" href="javascript:void(0)" onclick="pass(\'' + row.uniCode + '\')"><i class="fa fa-remove"></i>查看密码</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.queryParams = params;
        $.table.init(options);
    });

    /* 更新状态 */
    function updateStatus(id) {
        $.modal.open("更新订单状态", "order/orderStatus/"+id, '400', '200');
    }

    /* 查看订单详情 */
    function detail(id) {
        $.modal.open("查看订单详情", "order/orderInfo/"+id);
    }

    function remove(id){
        $.modal.confirm("确定删除该条信息吗？", function() {
            var config = {
                url: prefix+'/'+id,
                type: "DELETE",
                dataType: "json",
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                },
                success: function(result) {
                    if(result.code == 0){
                        parent.$.modal.msgSuccess("删除成功");
                        $.table.refresh();
                        $.modal.closeLoading();
                    }
                }
            };
            $.ajax(config)
        });
    }

    function pass(code) {
        layer.confirm("密码为：【 "+code+" 】", {
            btn: ['关闭'] //按钮
        }, function(){
            layer.closeAll()
        });
    }
</script>
</body>
</html>